package com.ruoyi.web.controller.booking;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Booking;
import com.ruoyi.system.service.IBookingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author Eugene
 * @date 2023-04-14
 */
@Api(tags="预约信息")
@RestController
@RequestMapping("/booking/booking")
public class BookingController extends BaseController
{
    @Autowired
    private IBookingService bookingService;

    /**
     * 查询预约信息列表
     */
    @ApiOperation("查询预约信息列表")
    @PreAuthorize("@ss.hasPermi('booking:booking:list')")
    @GetMapping("/list")
    public TableDataInfo list(Booking booking)
    {
        startPage();
        List<Booking> list = bookingService.selectBookingList(booking);
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('booking:booking:export')")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Booking booking)
    {
        List<Booking> list = bookingService.selectBookingList(booking);
        ExcelUtil<Booking> util = new ExcelUtil<Booking>(Booking.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    @ApiOperation("获取预约信息详细信息")
    @PreAuthorize("@ss.hasPermi('booking:booking:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookingService.selectBookingById(id));
    }

    /**
     * 新增预约信息
     */
    @ApiOperation("新增预约信息")
    @PreAuthorize("@ss.hasPermi('booking:booking:add')")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Booking booking)
    {
        return toAjax(bookingService.insertBooking(booking));
    }

    /**
     * 修改预约信息
     */
    @ApiOperation("修改预约信息")
    @PreAuthorize("@ss.hasPermi('booking:booking:edit')")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Booking booking)
    {
        return toAjax(bookingService.updateBooking(booking));
    }

    /**
     * 删除预约信息
     */
    @ApiOperation("删除预约信息")
    @PreAuthorize("@ss.hasPermi('booking:booking:remove')")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookingService.deleteBookingByIds(ids));
    }
}
